/**
 * 
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IActivityInvitationDao;
import com.qiyou.dao.impl.ActivityInvitationDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.ActivityInvitation;
import com.qiyou.util.DBUtil;

/**
 * 活动邀请数据操作代理
 * 
 * @author 赛艳志
 * 
 */
public class ActivityInvitationDaoProxy implements IActivityInvitationDao {
    private Connection conn = null;
    private IActivityInvitationDao dao = null;

    public ActivityInvitationDaoProxy(IDatabase database) {
        this.conn = database.getConnection();
        this.dao = new ActivityInvitationDaoImpl(conn);
    }

    @Override
    public boolean doCreate(ActivityInvitation activityInvitation)
            throws SQLException {
        if (null != activityInvitation) {
            try {
                return dao.doCreate(activityInvitation);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doUpdate(long acID, String userID, String state)
            throws SQLException {
        if ((null != userID) && (null != state) && (acID > 0)) {
            try {
                return dao.doUpdate(acID, userID, state);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doDelete(long acID, String userID) throws SQLException {
        if ((acID > 0) && (null != userID)) {
            try {
                return dao.doDelete(acID, userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public List<ActivityInvitation> getInvitations(long acID)
            throws SQLException {
        if (acID > 0) {
            try {
                return dao.getInvitations(acID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<ActivityInvitation> getInvitations(String userID)
            throws SQLException {
        if (null != userID) {
            try {
                return dao.getInvitations(userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<ActivityInvitation> getInvitations(Object... params)
            throws SQLException {
        if ((null != params)) {
            try {
                return dao.getInvitations(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

}
